Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bca/space explore pagination #3926

Merged
merged 7 commits into from
Sep 2, 2021

Conversation

BillCarsonFr
Copy link
Member

Fixes #3693

This PR add supports for the Space Summary API pagination (deprecation of org.matrix.msc2946/rooms/{roomId}/spaces in favor of org.matrix.msc2946/rooms/{roomId}/hierarchy)

Element Android only uses the hierarchy API with depth 1.
The pagination is triggered seamlesly when the user reaches the last item of the list (using epoxy visibility tracker on a bottom loading item). Pagination results are cached and kept in memory as long as the screen is visible.

This PR is also doing a quick cleaning by removing support for auto-join, that has been postponed for a later release

Here is a sample with some low page size:
sum_pagination

@BillCarsonFr BillCarsonFr added A-Spaces Spaces, groups, communities Z-NextRelease For issues and PRs which should be included in the NextRelease. labels Aug 31, 2021
@BillCarsonFr BillCarsonFr requested a review from bmarty August 31, 2021 13:56
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few remarks from a static review. Also the CI was not happy, can you have a look please?

* @param limit a client-defined limit to the maximum number of rooms to return per page. Must be a non-negative integer.
* @param maxDepth: Optional: The maximum depth in the tree (from the root room) to return.
* @param from: Optional. Pagination token given to retrieve the next set of rooms. Note that if a pagination token is provided,
* then the parameters given for suggested_only and max_depth must be the same.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_depth is not a part of this API, the SDK forces the value to 1.
So either expose max_depth to the client applications here, or update this comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed comment

// }
// }
// }
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it worth commenting all the code about auto-join? Maybe just make sure that the value is always set to false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto-join was removed and will probably not be designed like this, I commented out just to remember where it was done to help future implementation

}.orEmpty()
}
.orEmpty()
SpaceHierarchySummary(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpaceHierarchySummary name is a bit confusing to me (at least at first sight). I proposeSpaceHierarchyData, WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


internal interface SpaceApi {

/**
* @param limit: Optional: a client-defined limit to the maximum number of rooms to return per page. Must be a non-negative integer.
* @param max_depth: Optional: The maximum depth in the tree (from the root room) to return.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxDepth is the actual parameter name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

* The fields are the same as those returned by /publicRooms (see spec), with the addition of:
* room_type: the value of the m.type field from the room's m.room.create event, if any.
* children_state: The m.space.child events of the room.
* For each event, only the following fields are included1: type, state_key, content, room_id, sender,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in included1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -62,7 +62,7 @@ class SpaceCardRenderer @Inject constructor(
inCard.matrixToAccessImage.isVisible = true
inCard.matrixToAccessImage.setImageResource(R.drawable.ic_room_private)
}
val memberCount = spaceSummary.otherMemberIds.size
val memberCount = spaceSummary.joinedMembersCount?.let { it - 1 } ?: 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why decrementing the value here? Maybe add a comment to clarify

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The summay object here is constructed from space summary API, so it does not have all the info as a real summary from DB would have (like the list of user ids of members). So I switched to using joinedMembersCount, but i believe that joinedMemberCount is counting current user unlike otherMemberIds, so decremented to keep same result as before.
I'll check if I can't just use that number indeed

errorWithRetryItem {
id("error_${currentRootId}_${hierarchySummary.nextToken}")
text(host.errorFormatter.toHumanReadable(paginationStatus.error))
listener { host.listener?.retry() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think calling retry() is not correct here, you should call host.listener?.loadAdditionalItemsIfNeeded()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be on the safe side and retry all since the beginning, but I can just retry pagination

session.getRoomSummary(it.childRoomId)
?.takeIf { it.membership == Membership.JOIN } // only take if joined because it will be up to date (synced)
}
}.distinctBy { it.roomId }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding this call to distinctBy()? The server can send duplicates? If it is the case, it's probably better to handle that SDK side.

errorWithRetryItem {
id("error_$nextToken")
text(host.errorFormatter.toHumanReadable(paginationStatus.error))
listener { host.listener?.retry() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

host.listener?.loadAdditionalItemsIfNeeded() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@BillCarsonFr BillCarsonFr force-pushed the feature/bca/space_explore_pagination branch from 575f600 to 1c7e567 Compare September 2, 2021 09:56
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

@bmarty bmarty merged commit d87ca40 into develop Sep 2, 2021
@bmarty bmarty deleted the feature/bca/space_explore_pagination branch September 2, 2021 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Spaces Spaces, groups, communities Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

M11.4 Spaces | Space summary pagination
2 participants